class student:
    def __init__(self,filename,mode):
        self.filename=filename
        self.mode=mode
    def __str__(self):
        return f'我是{self.name}'
    def __call__(self,*args,**kwargs):
        for i in args:
            print(f"我{self.name}有个位置参数叫{i}")
        for i in kwargs:
            print(f"我{self.name}有个关键字参数{i}:{kwargs[i]}")
    def __enter__(self): # 调用者本身
        self.file=open(self.filename,self.mode)
        return self.file
    def __exit__(self,exc_type,exc_val,exc_tb):
        if self.file:
            self.file.close()
# 使用上下文管理器
with student('D://1.txt','w') as file:
    file.write('Hello world!')